package com.itmuch.youran.exception.aop;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import com.itmuch.core.converter.AjaxResult;
import com.itmuch.core.exception.BaseException;

@ControllerAdvice
public class ErrorHandler extends ResponseEntityExceptionHandler {

	@ExceptionHandler(value = BaseException.class)
	@ResponseBody
	public AjaxResult<Object> errorResponse(BaseException exception) {
		return new AjaxResult<Object>().error("异常发生.", exception.getMessage(), exception.getErrorCode());
	}

}
